#include ".MODULE/cpp/wa_interface.h"

#include "cpp_asset_counter.h"
#include "../../Counter.hpp"

/************* Function Block cpp_asset_counter *************/

cpp_asset_counter_Base *new_FB_cpp_asset_counter(cpp_asset_counter_Data *data) {
    /* Add initialization logic here if needed */
    return new class cpp_asset_counter();
}

cpp_asset_counter::cpp_asset_counter(): cpp_asset_counter_Base() {
    pImpl = new Counter();
}

cpp_asset_counter::~cpp_asset_counter() {
    delete (Counter *)(pImpl);
}

void cpp_asset_counter::call(cpp_asset_counter_Data *data) {
    Counter *counter = (Counter *)pImpl;
    counter->IN1 = data->IN1;
    counter->do_count();
    data->CNT = counter->CNT;
}

int cpp_asset_counter::save(void *buffer, int size) {
    Counter *counter = (Counter *)pImpl;
    *(DINT *)buffer = counter->CNT;
    return sizeof(DINT);
}

bool cpp_asset_counter::restore(void *instance_data, int size) {
    Counter *counter = (Counter *)pImpl;
    counter->CNT = *(DINT *)instance_data;
    return true;
}

/*********** End Function Block cpp_asset_counter ***********/
